<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Verifier_model extends CI_Model {


	public function verify_login($username,$password)
	{
		//return array('username'=>$username,'password'=>$password);
		$sql = "SELECT * FROM account WHERE username=? AND password=?";
		$query = $this->db->query($sql,array($username,$password));
		
		return $query->result_array();
	}
	
	public function verify_email($username)
	{
		
		$sql = "SELECT * FROM account WHERE username=?";
		$query = $this->db->query($sql,$username);
		
		if($query->num_rows()>=1){
			return true;
		}else{
			return false;
		}
		
	}
	
	public function has_students($accid)
	{
		
		$sql = "SELECT * FROM student WHERE guardian_id IN (SELECT guardian_id FROM `guardian` WHERE account_id = ?)";
		$query = $this->db->query($sql,$accid);
		
		if($query->num_rows()>=1){
			return true;
		}else{
			return false;
		}
		
	}
	
	public function has_token($guardian_id)
	{
		
		$sql = "SELECT * FROM api_access t1
INNER JOIN guardian t2
ON t2.contact_number LIKE CONCAT('%', t1.subscriber_number, '%')
WHERE t2.guardian_id=?";
		$query = $this->db->query($sql,$guardian_id);
		
		if($query->num_rows()>=1){
			return true;
		}else{
			return false;
		}
		
	}

	public function verify_login_return_info($username,$password)
	{
		// return array('username'=>$username,'password'=>$password);
		$retData=array();
		//$debug_sql="SELECT * FROM account WHERE username='".$username."' AND password='".$password."'";
		$sql = "SELECT * FROM account WHERE username=? AND password=?";
		$query = $this->db->query($sql,array($username,$password));
		if($query->result_array()!=null){
			$firstArray = $query->result_array();
			
			$accountID = $firstArray['0']['account_id'];

			$retData = $this->getGuardianByAcctID($accountID);
			// print_r("<pre>");
			// print_r($retData);
			// print_r("</pre>");

		}
		return $retData;
	}

	public function getGuardian($gID){
		$sql = "SELECT * FROM guardian WHERE guardian_id=?";
		$query = $this->db->query($sql,array($gID));
		return $query->result_array();
	}

	public function getGuardianByAcctID($gID){
		$sql = "SELECT * FROM guardian WHERE account_id=?";
		$query = $this->db->query($sql,array($gID));
		return $query->result_array();
	}

	public function getStudent($sID){
		$sql = "SELECT * FROM student WHERE student_id=?";
		$query = $this->db->query($sql,array($sID));
		return $query->result_array();
	}
	
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */